<?php 
	include_once 'dataservice.php';
	include_once 'thuvienham.php';

	class trangthai_db 
	{
		public function Them($MaTrangThai, $TenTrangThai)
		{
			$sql = "INSERT INTO `tbl_trangthai`(`MaTrangThai`, `TenTrangThai`)
					VALUES ('$MaTrangThai', '$TenTrangThai')";

			$service = new dataservice();
			return $service->ExecuteNonQuery($sql);
		}

		public function Xoa($MaTrangThai)
		{
			$sql = "DELETE FROM `tbl_trangthai` WHERE `MaTrangThai` = '$MaTrangThai'";

			$service = new dataservice();
			return $service->ExecuteNonQuery($sql);
		}

		public function CapNhat($MaTrangThai, $TenTrangThai)
		{
			$sql = "UPDATE `tbl_trangthai`
					SET `TenTrangThai` = '$TenTrangThai'
					WHERE `MaTrangThai` = '$MaTrangThai'";

			$service = new dataservice();
			return $service->ExecuteNonQuery($sql);
		}

		public function LayDanhSach($MaTrangThai, $TenTrangThai)
		{
			$sql = "SELECT * FROM `tbl_trangthai` WHERE 1  ";
			if($MaTrangThai != -1)
				$sql .= " AND `MaTrangThai` = '$MaTrangThai' ";

			if($TenTrangThai != "")
				$sql .= " AND `TenTrangThai` = '$TenTrangThai' ";

			$service = new dataservice();
			return $service->ExecuteQuery($sql);
		}

	}

